Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Javascript function returning [object HTMLSelectElement] string instead of <select> HTML tag

I´m trying to create and call a function that builds a <select> item and returns this item to be rendered on the screen.

However, it renders the text "[object HTMLSelectElement]" on the screen instead of the <select> element that I want. In the Chrome console, though, it renders the <select> element perfectly.

function renderSelect(selectOptions) {
  var select = document.createElement("select");

  for (let index = 0; index < selectOptions.length; index++) {
    const element = selectOptions[index];

    select.insertAdjacentHTML(
      "beforeend",
      `<option value="${element}">${element}</option>`
    );
  }

  // This shows the <select> element perfectly in the console
  console.log(select)

  return select;
}

////////// BELOW IS THE FUNCTION CALL IN ANOTHER (WHICHEVER) PART OF THE CODE

// This renders "[object HTMLSelectElement]" on the screen instead of the <select> element
`${renderSelect(selectOptions)}`;
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda